package efuliBusiness;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import impl.TestServerBusinessImpl;
import models.MyConfig;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by yangxianming on 2018/5/11.
 */
public class Pay implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        JSONObject returnJson = JSON.parseObject("{\"apistatus\":0,\"result\":\"\",\"errorMsg\":\"\"}");

        //读取请求json
        InputStreamReader inputStreamReader;
        BufferedReader bufferedReader;
        String requestInfo = "";

        try {
            inputStreamReader = new InputStreamReader(request.getInputStream(), "UTF-8");
            bufferedReader = new BufferedReader(inputStreamReader);
            String line;
            while ((line = bufferedReader.readLine()) != null)
                requestInfo = requestInfo + line;

            //-----
//            String appPath = myConfig.getPropertiesConfig().getProperties().getProperty("appPath");
//            System.out.println(appPath);
//            System.setProperty("webdriver.chrome.driver", appPath + "\\resource\\chromedriver.exe");
//            WebDriver wb = new ChromeDriver();
//            wb.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//            wb.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//            wb.get("http://koufudev.e-fuli.com:8081/#/login");

        }catch (Exception e){
            //请求流如果出现异常的时候
            returnJson.put("apistatus", "0");
            returnJson.put("errorMsg", e.getMessage());
            return returnJson.toString();
        }

        //解析json对象
        returnJson.put("apistatus", "1");
        JSONObject apiJson = JSON.parseObject(requestInfo);
        System.out.println(apiJson);

        return returnJson.toString();
    }
}
